

function login() {
	var userName = dwr.util.getValue("userName");
	HostServiceCenter.login(userName);
}

function _callbackOnLoad(userName){
	if(userName){
		//alert(status);
		showMainPage(userName);
	}
}
var isUpdateComplete =  true;
var checkFUTimerID = null;
var checkFUSec = 30;
var checkFUTimerRunning = false;
	
	
function checkForUpdate(){
	if(isUpdateComplete){
		//alert("calling update --  " +isUpdateComplete);
		var gameCenterVersion =0;
		var roomVersion =0;
		var mainPage = ComponentManager.getComponentById("mainframe_instance");
		var room = ComponentManager.getComponentById("room_instance");
		if(mainPage != null){
			gameCenterVersion = mainPage.version;
		}
		if(room != null){
			roomVersion = room.version;
		}
		isUpdateComplete =  false;
		InitCheckForUpdateTimer();
		HubCenter.getUpdated(gameCenterVersion,roomVersion,updateCompletedCallBack,ErrorHandleForCheckUpdate);
		
	}
}

function ErrorHandleForCheckUpdate(){
	window.alert("Check For Update have some error!");
	isUpdateComplete =  true;
	StopCheckForUpdateTimer();
	setInterval("checkForUpdate()",5000);
}

function InitCheckForUpdateTimer(){
		checkFUSec = 30;
		StartCheckForUpdateTimer();
}

function StartCheckForUpdateTimer(){
    if (checkFUSec==0){
        StopCheckForUpdateTimer();
    }
    else{
    	checkFUSec = checkFUSec - 1;
    	checkFUTimerRunning = true;
        checkFUTimerID = setTimeout(StartCheckForUpdateTimer, 1000);
    }
}

function StopCheckForUpdateTimer(){
	if(checkFUTimerRunning){
		clearTimeout(checkFUTimerID);
		checkFUTimerRunning = false;
	}
	isUpdateComplete = true; 
}

function updateCompletedCallBack(){
	//alert("calling update --  " +isUpdateComplete);
	isUpdateComplete =  true;
	StopCheckForUpdateTimer();
}

function afterQuit(){
	//clientSideInclude('deskfarme', 'gameWindow.html');
	$('sidebar').style.display = '';
	$('sidebar').style.width = '100%';
	
	$('content').style.display = 'none';
	$('content').style.width = '0%';
}

function showMainPage(userName) {
	//window.location = "/dashboard.html?userName="+userName;
}

function redirectToLogin(userName){
	window.location = "/insightgoogle/login?userName="+userName;
}

function loginNameAlreadyExist(msg) {
	document.getElementById("message").innerHTML = msg;
}

function clientSideInclude(id, url) {
	  var req = false;
	  // For Safari, Firefox, and other non-MS browsers
	  if (window.XMLHttpRequest) {
	    try {
	      req = new XMLHttpRequest();
	    } catch (e) {
	      req = false;
	    }
	  } else if (window.ActiveXObject) {
	    // For Internet Explorer on Windows
	    try {
	      req = new ActiveXObject("Msxml2.XMLHTTP");
	    } catch (e) {
	      try {
	        req = new ActiveXObject("Microsoft.XMLHTTP");
	      } catch (e) {
	        req = false;
	      }
	    }
	  }
	 var element = document.getElementById(id);
	 if (!element) {
	  alert("Bad id " + id +
	   "passed to clientSideInclude." +
	   "You need a div or span element " +
	   "with this id in your page.");
	  return;
	 }
	  if (req) {
	    // Synchronous request, wait till we have it all
	    req.open('GET', url, false);
	    req.send(null);
	    element.innerHTML = req.responseText;
	  } else {
	    element.innerHTML =
	   "Sorry, your browser does not support " +
	      "XMLHTTPRequest objects. This page requires " +
	      "Internet Explorer 5 or better for Windows, " +
	      "or Firefox for any system, or Safari. Other " +
	      "compatible browsers may also exist.";
	  }
	}

var newwindow;
function popWindow(url)
{
	newwindow=window.open(url,'name','height=300,width=400');
	if (window.focus) {newwindow.focus()}
}
